import torch.nn as nn
from resnet18_backbone import Resnet18
from PiCANet import GlobalPiCANet, LocalPiCANet

class PiCANetResnet18(nn.Module):
    def __init__(self):
        super().__init__()
        self.backbone = Resnet18()
        self.global_pica = GlobalPiCANet(in_channels=256)
        self.local_pica = LocalPiCANet(in_channels=512)
        self.pred_conv = nn.Conv2d(512, 1, kernel_size=1)  # 1x1卷积层定义在这里

    def forward(self, x):
        x1, x2, x3, x4 = self.backbone(x)
        x3 = self.global_pica(x3)
        x4 = self.local_pica(x4)
        pred = self.pred_conv(x4)
        pred = nn.functional.interpolate(pred, size=(224, 224), mode='bilinear', align_corners=False)
        return pred

